﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ITOMMS.Entity;
using Watson.Core.Tools;
using ITOMMS.Business;

namespace ITOMMS.Web.UserManage
{
    public partial class SoftWareAdd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {


                if (Request.Params["id"] != null)
                {
                    string sid = Request.Params["id"].ToString();
                    int pid = 0;
                    if (int.TryParse(sid, out pid))
                    {
                        DataShow(pid);
                    }
                }
                if (Request.Params["vid"] != null)
                {
                    string sid = Request.Params["id"].ToString();
                    int pid = 0;
                    if (int.TryParse(sid, out pid))
                    {
                        btnSave.Visible = false;
                        DataShow(pid);
                    }
                }
            }
        }

        private void DataShow(int id)
        {
            tb软件清单Entity entity = new tb软件清单Entity();
            entity = new tb软件清单Entity().GetById(id);
            ViewState["Entity"] = entity;

            txtSoftName.Text = entity.SoftName;
            ddlSoftType.Items.FindByValue(entity.SoftType.ToString());

            txtRemarks.Text = entity.Remarks;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                tb软件清单Entity entity = new tb软件清单Entity();
                if (ViewState["Entity"] != null)
                {
                    entity = ViewState["Entity"] as tb软件清单Entity;
                }
                else
                {
                    entity.CreateBy = SessionHelper.UserID;
                    entity.CreateDate = DateTime.Now;
                }
                entity.SoftName = txtSoftName.Text;
                entity.SoftType = ddlSoftType.SelectedValue.ToString();

                entity.Remarks = txtRemarks.Text.Trim();
                entity.SaveOrUpdate(entity);
                ViewState["Entity"] = entity;
                entity.ModifyBy = SessionHelper.UserID;
                entity.ModifyDate = DateTime.Now;
                MessageboxInfo.MessageBox(this, MessageType.SUCCEEDED, "保存成功");
            }
            catch (Exception ex)
            {
                log4netHelper.error(ex);
                MessageboxInfo.MessageBox(this, MessageType.ERROR, "保存失败");
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("SoftWareList.aspx", true);
        }

        
    }
}
